package chapter5

import (
	"fmt"
	"sync"
	"time"
)

func Test3()  {
	//数组的指针可以直接访问数组中的元素
	nums:=[3]int{1,2,3}
	p:=&nums
	fmt.Println(p[0],p[1],p[2])
	fmt.Println("------------------------")
	ans:=[]int{1,2,3,4,5,6,7,8,9}
	fmt.Println(ans[1:3:7],len(ans[1:3:7]))
	fmt.Println("-----------------------")
	fmt.Println(cap([]int{1,2,3}),cap([2]int{1,2}),len(map[string]int{"a":1}))
	fmt.Println("----------------------------------")
	var lock sync.RWMutex
	m1:=make(map[int]int)
	go func() {
		for  {
			lock.Lock()
			m1[2]+=1
			lock.Unlock()
			time.Sleep(time.Second)
		}
	}()
	go func() {
		for  {
			lock.RLock()
			fmt.Println(m1[2])
			lock.RUnlock()

			time.Sleep(time.Second)
		}

	}()
}